﻿@using WeBlog.Models
@model IEnumerable<WeBlog.Models.BlogPost>

@{
    ViewBag.Title = "Index";
}
<h2>@ViewBag.Title</h2>
<h3>@ViewBag.Message</h3>

<p>
    @if (Model.Any())
    {
        @Html.ActionLink(Model.FirstOrDefault().Title, "Details", "BlogPost", new {blogPostId = Model.FirstOrDefault().Id}, null)
        <br />
        @Html.DisplayFor(modelItem => Model.ToArray()[0].Body)
        <br/><br/>
    
        @Html.DisplayNameFor(model => model.ImagePath)
        foreach (var item in Model)
        {
            BlogPost item1 = item;
            @Html.DisplayFor(modelItem => item1.ImagePath)
        }        

        <br/><br/>
        
        <div style="font-size: small">Posted: @Html.DisplayFor(modelItem => Model.ToArray()[0].BlogDateTime,"ShortDateTime")<br/>
        External Link: @Html.DisplayFor(modelItem => Model.ToArray()[0].ExternalLink)
        </div>
    }
</p>

<table class="table">
    
@for (int i=1; i<Model.Count();i++) {
    <tr>
        <td>
            @Html.ActionLink(Model.ToArray()[i].Title, "Details", "BlogPost", new { blogPostId=Model.ToArray()[i].Id }, null)
            <br/>
            @Html.DisplayFor(modelItem => Model.ToArray()[i].Body)
            <br/><br/>

             <div style="font-size: small">Posted: @Html.DisplayFor(modelItem => Model.ToArray()[i].BlogDateTime,"ShortDateTime")<br/>
                External Link: @Html.DisplayFor(modelItem => Model.ToArray()[i].ExternalLink)
            </div>
       </td>
    </tr>
}

</table>
